<?php

class User_model extends CI_Model 
{
    function __construct()
    {
        parent::__construct();
    }
	
	function get_users($page, $search_by = null, $search_value = null)
	{
		$this->db->from('user');
		$this->db->join('person', 'user.person_id = person.id');
		$this->db->join('department', 'user.department_id = department.id');
		$this->db->select('user.id as id, username, first_name, last_name, employee_id, department.name as department_name');
		$this->db->limit(20, ($page - 1) * 20);
		
		if($search_by && $search_value)
			$this->db->where($search_by . " LIKE '%" . $search_value . "%'");
		
		$query = $this->db->get();
		
		return $query->result();
	}
	
	function create($data)
	{
		$this->db->insert('user', $data);
		return $this->db->insert_id();
	}	
	
	function delete($id)
	{
		$this->db->where('id', $id);
		$this->db->delete('user');
	}
}